#include <stdio.h>
#include <stdlib.h>
#include <memory.h>

typedef unsigned short bool;
#define true    1
#define false   0

int n;

int p, q;

short chessboard[26][26];


void init_chessboard()
{
    int i, j;
    for(i = 0; i < p; ++i)
    {
        for(j = 0; j < q; ++j)
            chessboard[i][j] = 0;
    }
}

void print_chessboard()
{

    int i, j;
    printf("-------begine---------\n");
    for(i = 0; i < p; ++i)
    {
        for(j = 0; j < q; ++j)
            printf("%d", chessboard[i][j]);
        printf("\n");
    }
    printf("-------end---------\n");
}

bool check_all_visited()
{
    int i, j;
    for (i = 0; i < p; ++i)
    {
        for(j = 0; j < q; ++j)
            if (chessboard[i][j] == 0)
                return false;
    }
    return true;
}


void visited_ij(int i, int j)
{
    chessboard[i][j]++;
}

void unvisited_ij(int i, int j)
{
    chessboard[i][j]--;
}

/*
 * 寻找从位置(x,y)移动一次能够到达的位置集合
 * 如果集合为空，则表示遍历又此结点为根结点的遍历结束，
 * 应回退到上一结点
 */
bool travel_from_ij(int i, int j)
{
    unsigned short set[8][2];
    unsigned short count = 0;
    visited_ij(i, j);
    print_chessboard();


    if (i-2 >= 0 && j-1 >= 0 && 
            chessboard[(i-2)][ j-1] == false)
    {
        set[count][0] = i-2;
        set[count][1] = j-1;
        count++;
    }

    if (i-2 >= 0 && j+1 < q && 
            chessboard[(i-2)][j+1] == false)
    {
        set[count][0] = i-2;
        set[count][1] = j+1;
        count++;
    }

    if (i-1 >= 0 && j-2 >= 0 && 
            chessboard[(i-1)][j-2] == false)
    {
        set[count][0] = i-1;
        set[count][1] = j-2;
        count++;
    }

    if (i-1 >= 0 && j+2 < q && 
            chessboard[(i-1)][j+2] == false)
    {
        set[count][0] = i-1;
        set[count][1] = j+2;
        count++;
    }

    if (i+1 < p && j-2 >= 0 && 
            chessboard[(i+1)][j-2] == false)
    {
        set[count][0] = i+1;
        set[count][1] = j-2;
        count++;
    }

    if (i+1 < p && j+2 < q && 
            chessboard[(i+1)][j+2] == false)
    {
        set[count][0] = i+1;
        set[count][1] = j+2;
        count++;
    }

    if (i+2 < p && j-1 >= 0 && 
            chessboard[(i+2)][j-1] == false)
    {
        set[count][0] = i+2;
        set[count][1] = j-1;
        count++;
    }

    if (i+2 < p && j+1 < q && 
            chessboard[(i+2)][j+1] == false)
    {
        set[count][0] = i+2;
        set[count][1] = j+1;
        count++;
    }

    {
        printf("结点%d %d能够访问的结点数:%d\n", i, j, count);
        for (i = 0; i < count; ++i)
            printf("(%d %d)\t", set[i][0], set[i][1]);
        printf("...\n");
    }

    if (count == 0)
    {
        if (check_all_visited() == false)
        {
            unvisited_ij(i, j);
            return false;
        }
        else
            return true;
    }

    for (i = 0; i < count; ++i)
    {
        if (travel_from_ij(set[i][0], set[i][1]))
            return true;
        else
        {
            continue;
        }
    }
    unvisited_ij(i, j);
    return false;
}

bool travel()
{
    int i, j;
    for (i = 0; i < p; ++i)
    {
        for (j = 0; j < q; ++j)
        {
            printf("从%d %d处开始.\n", i, j);
            init_chessboard();
            if (travel_from_ij(i, j) == true)
            {
                printf("Success.\n");
                return true;
            }
        }
    }
    printf("Failed.\n");
    return true;
}

int main(void)
{
    freopen("bin/2488.in", "r", stdin);
    int i;

    scanf("%d", &n);
    for(i = 0; i < n; ++i)
    {
        scanf("%d %d", &p, &q);
        travel();
    }
    return 0;
}
